
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%@page import="com.tss.util.*"%>
<%@page import="com.jedi.*"%>
<%@page import="com.store.*"%>
<%@page import="java.util.*"%>
<%@page import="java.text.*"%>
<%@include file="../global_var.jsp"%>
<%@include file="../check_login.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
User just_user = (User)session.getAttribute("LoginUser");
String edate = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
Calendar calen = Calendar.getInstance();
calen.setTime(TSSDate.parseDate(edate));
calen.add(Calendar.MONTH, -1);
String bdate = new SimpleDateFormat("yyyy-MM-dd").format(calen.getTime());
ContractMgr contractMgr = new ContractMgr();
List list = null;
String area_id       = ParamUtils.getParameter(request,"area_id","");

int status     = ParamUtils.getIntParameter(request,"status",0);
int comid     = ParamUtils.getIntParameter(request,"comid",0);
String conid   = ParamUtils.getParameter(request,"conid","");
String service_id    = ParamUtils.getParameter(request,"service_id","");
String customer = ParamUtils.getParameter(request,"customer","");
String saleid      = ParamUtils.getParameter(request,"saleid","");
String begin_date    = ParamUtils.getParameter(request,"begin_date",bdate);
String end_date      = ParamUtils.getParameter(request,"end_date",edate);
String techmanager    = ParamUtils.getParameter(request,"techmanager","");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    
    <title>My JSP 'techcontract_list.jsp' starting page</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    
   <link href="style/main.css" rel="stylesheet" type="text/css">
<script language="javascript" src="js/common.js"></script>
<script language="javascript">
function clk_contract_show(id) {
	right_menu_clk("incon_show.jsp?conid="+ id);
}
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
	 <td >
		<form name="pageForm" method="post">
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td height="100" valign="top" align="center" style="padding-top:12px;padding-bottom:10px;">
								
					<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
					<tr bgcolor="#EDEDF0">
						<td height="24" style="padding-left:10px;">
						
						
					所在区域：
                  <select name="area_id" onchange="pageForm.submit();">
                   <option value="">=全部=</option>
                    <%for(int i=0;i<area_item_info.length;i++){%>
                    <option value="<%=area_item_info[i]%>"<%if (area_id.trim().equals(area_item_info[i])){%> selected<%}%>><%=area_item_info[i]%></option>
                    <%}%>
                  </select>
                  
                  合同状态：
                  <select name="status">
                   <option value="1" <%if (status==1){%> selected<%}%>>未分配</option>
                     <option value="2" <%if (status==2){%> selected<%}%>>已分配</option>
                    
                  </select>
				     销售员：
            	      <select name="saleid" >
            	        <option value="">全部</option>
            	        <%
            	        UserMgr userMgr = new UserMgr();
            	        String saler="saler";
            	        List userList = userMgr.getUsersGroupbyroleid(saler);
            	        if (userList != null && userList.size() > 0) {
                    		for(int i=0;i<userList.size();i++){
                    			User item = (User)userList.get(i);
                    	%>
                        <option value="<%=item.getId()%>"<%if (item.getId().trim().equals(saleid)) {%> selected<%}%>><%=item.getUserName()%></option>
                    	<%}}%>
            	      </select>
            	      &nbsp; 登记时间：<span id="htmlBeginTime">从 
													<input type="text" name="begin_date" size="10" maxlength="15" value="<%=begin_date%>" readonly style="background-color:#EDEDE8"> 
													</span> <a href="javascript:void(0)"
														onClick="gfPop.fPopCalendar(document.forms[0].begin_date);return false;" HIDEFOCUS>&nbsp;<img name="popcal" align="bsBottom" src="calendar/calbtn.gif" width="18" height="18" border="0" alt=""></a> 到 <span id="htmlEndTime"> 
													<input type="text"
															name="end_date" size="10" maxlength="" value="<%=end_date%>" readonly style="background-color:#EDEDE8"> </span> <a href="javascript:void(0)" onClick="gfPop.fPopCalendar(document.forms[0].end_date);return false;" HIDEFOCUS>&nbsp;<img
															name="popcal" align="Bottom" src="calendar/calbtn.gif" width="18" height="18" border="0" alt=""></a>&nbsp;&nbsp;&nbsp;&nbsp;
													<input type="submit" class="inputButton" value="确定">
            	      </td>
				  </tr>
		
					 <tr bgcolor="#FFFFFF">
					<td height="15" style="padding-left:10px;" colspan="4">
					</td>
					</tr>
				</table>

				<table width="100%" border="0" cellpadding="0" cellspacing="1"
					bgcolor="#FFFFFF">
					<tr align="center" bgcolor="#858585">
					<td width="15%"><font color="#FFFFFF">客户名称</font></td>
						<td width="15%" height="24"><font color="#FFFFFF">服务合同号</font></td>
						<td width="15%" height="24"><font color="#FFFFFF">登记时间</font></td>
						
						<td width="8%"><font color="#FFFFFF">联系人</font></td>
						<%if(status==2){%>
						<td width="8%"><font color="#FFFFFF">项目经理</font></td>
						<%}%>
						<td width="8%"><font color="#FFFFFF">销售员</font></td>
						<td width="8%"><font color="#FFFFFF">厂商名称</font></td>
						<td width="8%"><font color="#FFFFFF">初次安装费</font></td>
						<td width="8%"><font color="#FFFFFF">备件成本</font></td>
						<td width="6%"><font color="#FFFFFF">操作</font></td>
					</tr>
					<%
				 String otherSQL = " and techmanager ='"+just_user.getId()+"' and contype=1";
				 if(just_user.getRoleId().trim().equals("TM")||just_user.getRoleId().trim().equals("admin")){
				    otherSQL="and contype=1";
				 }
				 	if (comid !=0) otherSQL += " and t.comid = '" + comid+ "'";
				 	if (status==1) otherSQL += " and t.techmanager =''";
				 		if (status==2) otherSQL += " and t.techmanager !=''";
				 		if (! techmanager.trim().equals("")) otherSQL += " and t.techmanager = '" + techmanager+ "'";
					if (!area_id.trim().equals("")) otherSQL += " and t.area = '" + area_id.trim() + "'";
					if (!conid.trim().equals("")) otherSQL += " and t.conid like '%" + conid.trim() + "%'";
					if (!service_id.trim().equals("")) otherSQL += " and t.serviceid like '%" + service_id.trim() + "%'";
					if (!customer.trim().equals("")) otherSQL += " and t.customer like '%" + customer.trim() + "%'";
					if (!saleid.trim().equals("")) otherSQL += " and t.saleid = '" + saleid + "'";
					if (!begin_date.trim().equals("")) otherSQL += " and substring(t.createtime for 10) >= '" + begin_date.trim() + "'";
					if (!end_date.trim().equals("")) otherSQL += " and substring(t.createtime for 10) <= '" + end_date.trim() + "'";
					     
              String orderField = "t.createtime desc";
              int pageSize = 10;
              int pageno=1;
               String page2=request.getParameter("mgh");
            	
              	
              		if(page2==null||page2==""){
              				pageno=1;
              				}
              			else{
              					pageno=Integer.parseInt(page2);
              				}
              				

            	
              int pageNo = ParamUtils.getIntParameter(request,"page",pageno);
              	             String pageno1 = String.valueOf(pageNo); 
							session.setAttribute("pageno1",pageno1);
              list = contractMgr.get(otherSQL,orderField,pageNo,pageSize);
              
              int total = contractMgr.getTotal(); 
              boolean b=(total % pageSize ==0);
              int pageCount=b?(total/pageSize):(total/pageSize +1);
              if(pageNo>pageCount){
              	pageNo=pageCount;
              }
              if (list != null && list.size() > 0) {
              	String bgColor[] = {"#EDEDF0","#D7D7DB"};
              	for(int i=0;i<list.size();i++) {
              		Contract item = (Contract)list.get(i);
              		Calendar cal = Calendar.getInstance();
              		cal.setTime(item.getSevenddate());
              		cal.add(Calendar.DAY_OF_MONTH,-10);
              		String imgAlert = "";
              		if (cal.getTimeInMillis() < System.currentTimeMillis())
              			imgAlert = " <img src=\"images/contract_alert.gif\">";
              %>
					<tr align="center" bgcolor="<%=bgColor[i%2]%>" onMouseOver="this.style.background='#efefef'" onMouseOut="this.style.background='<%=bgColor[i%2]%>'">
						<td height="24"><a
							href="incontract_mgt/incon_detail.jsp?conid=<%=item.getId()%>"><%=item.getCustomer()%></a>
						</td>
					
						<td><%=item.getServiceid()%></td>
							<td><%=item.getCreatetime()  + imgAlert%></td>
						<td><%=item.getLinkman()%></td>
							<%if(status==2){%>
						<td><%=item.getTechmanager_name()%></td>
						<%}%>
						<td><%=item.getSale_name()%></td>
						<td><%=item.getCom_name()%></td>
						
						<td align="right">￥<%=item.getFifee()%></td>
						<td align="right">￥<%=item.getSpartfee()%></td>
					
						<td><span onclick="clk_contract_show('<%=item.getId()%>');"
							style="cursor:hand;text-decoration: underline;">修改</span></td>
					</tr>
					<%}%>
				</table>
				<table width="99%" border="0" cellpadding="0" cellspacing="0" background="images/page_img/page_bk.gif">

										<tr height="32" align="center" valign="bottom">
											<td width="5%">
												<img src="images/page_img/page_tag_01.gif">


											</td>
											<td height="35" align="right" style="padding-right:10px;" valign="bottom" id="pannelPageInfo">
												&nbsp;
											</td>
										</tr>

									</table>
									<script language="javascript">
            							pannelPageInfo.innerHTML = getPageInfo(<%=total%>,<%=pageSize%>,<%=pageNo%>,5,'images/page_img','pageForm');
            						</script>
									<%} else {%>
					
								<table width="85%" border="0" cellpadding="4" cellspacing="1" bgcolor="#FFFFFF">
									<tr>
										<td height="60" align="center">
											请选择条件查询项目信息!
										</td>
									</tr>
								</table>
								<%}%>
							</td>
						</tr>

				</table>
					</form>
				</td>
			</tr>
		</table>

		
		<iframe width="168" height="190" name="gToday:normal:agenda.js" id="gToday:normal:agenda.js" src="calendar/ipopeng.htm" scrolling="no" frameborder="0"
			style="BORDER-RIGHT:2px ridge; BORDER-TOP:2px ridge; Z-INDEX:999; LEFT:-500px; VISIBILITY:visible; BORDER-LEFT:2px ridge; BORDER-BOTTOM:2px ridge; POSITION:absolute; TOP:0px">
		</iframe>
	</body>
</html>
